if (("onhashchange" in window) && !($.browser.msie)) {

    $.smConfig.router=false;

    function MyRouter(){

    }

    MyRouter.prototype.back=function(newPage,currentPage){
        this.animatePages(newPage, currentPage, true);
    }

    MyRouter.prototype.forward=function(newPage,currentPage){
        this.animatePages( currentPage,newPage);
    }
    MyRouter.prototype.animatePages = function (leftPage, rightPage, leftToRight) {
        var removeClasses = 'page-left page-right page-current page-from-center-to-left page-from-center-to-right page-from-right-to-center page-from-left-to-center';
        if (!leftToRight) {
            rightPage.trigger("pageAnimationStart", [rightPage[0].id, rightPage]);
            leftPage.removeClass(removeClasses).addClass('page-from-center-to-left');
            rightPage.removeClass(removeClasses).addClass('page-from-right-to-center');
            leftPage.animationEnd(function() {
                leftPage.removeClass(removeClasses);
            });
            rightPage.animationEnd(function() {
                rightPage.removeClass(removeClasses).addClass("page-current");
                rightPage.trigger("pageAnimationEnd", [rightPage[0].id, rightPage]);
                rightPage.trigger("pageInitInternal", [rightPage[0].id, rightPage]);
            });
        } else {
            leftPage.trigger("pageAnimationStart", [rightPage[0].id, rightPage]);
            leftPage.removeClass(removeClasses).addClass('page-from-left-to-center');
            rightPage.removeClass(removeClasses).addClass('page-from-center-to-right');
            leftPage.animationEnd(function() {
                leftPage.removeClass(removeClasses).addClass("page-current");
                leftPage.trigger("pageAnimationEnd", [leftPage[0].id, leftPage]);
                leftPage.trigger("pageReinit", [leftPage[0].id, leftPage]);
            });
            rightPage.animationEnd(function() {
                rightPage.removeClass(removeClasses);
            });
        }

    }

    $.myRouter = new  MyRouter();
    function initHash(){
        var hash = window.location.hash
        //$('.page').removeClass('page-current')
        hash = hash||'#page-main'
        $(hash).addClass('page-current');
    }
    initHash();



    $(document).on("click", "a", function(e) {
        var $target = $(e.currentTarget);
        if($target.hasClass("external") ||
            $target[0].hasAttribute("external") ||
            $target.hasClass("tab-link") ||
            $target.hasClass("open-popup") ||
            $target.hasClass("open-panel")
        ) return;
        var href=$target.attr('href')
        if(!href || href[0]!='#'){
            return;
        }
        e.preventDefault();
        var hash = $target.attr("href");


        var curPage =$('.page-current');
        var newPage = $(hash)
        if($target.hasClass("back")) {
            $.myRouter.back(newPage,curPage);
        }else{
            $.myRouter.forward(newPage,curPage)
        }

        history.replaceState(null, document.title, ('' + window.location).split('#')[0] + hash);
    })
}